/* Copyright 2006 Nicklas R Johnson
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */

package net.spatula.tally_ho.ui.article.read;

import net.spatula.tally_ho.service.beans.ArticleBean;
import net.spatula.tally_ho.ui.ExternalImage;
import net.spatula.tally_ho.ui.Mugshot;
import wicket.markup.html.basic.Label;
import wicket.markup.html.panel.Fragment;
import wicket.markup.html.panel.Panel;
import wicket.model.CompoundPropertyModel;
import wicket.model.PropertyModel;


/**
 * @author spatula
 *
 */
public class ArticleDisplayPanel extends Panel {

 
    private static final long serialVersionUID = 1L;

    public ArticleDisplayPanel(String arg0, ArticleBean article, Panel inline) {
        super(arg0);
        
        setModel(new CompoundPropertyModel(article));
        add(new Label("summary"));
        add(new Label("adjective"));
        add(new Label("username", new PropertyModel(article.getCreator(), "username")));
        add(new Label("createDate"));
        add(new Label("postCount"));
        add(new Label("body"){           

            private static final long serialVersionUID = 1L;

            {
                setEscapeModelStrings(false);
                
            }
        });
        
        Mugshot mug = new Mugshot();
        final String mugPath = mug.getMugshotPath(article.getCreator().getUsername());
        final String mugUser = article.getCreator().getUsername();
        
        System.out.println("Mug path:" + mugPath);
        
        if (mugPath != null) {
            Fragment mugfrag = new Fragment("mugshot", "hasMugshot");
            mugfrag.add(new ExternalImage("mug", mugPath, mugUser + " mugshot"));
            add(mugfrag);
        } else {
            add(new Label("mugshot","").setEnabled(false));
        }
        
        if (inline != null) {
            Fragment panelFrag = new Fragment("panel", "hasAdPanel");
            Panel adPanel = new Panel("adPanel");
            adPanel.add(inline);
            panelFrag.add(adPanel);
            add(panelFrag);
        } else {
            add(new Fragment("panel", "hasNoAdPanel"));
        }
        
        add(new VotePanel("vote", article));
        add(new ActionsPanel("actions", article));
        
    }


}
